Enforce UTF-8 encoding when opening C files
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 18 Jan 2018 19:23:16 +0000 (19:23 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 23 Jan 2018 13:04:49 +0000 (14:04 +0100)
We have a couple of Python 3.x scripts that parse C files, and since C
does not have any encoding, we need to force one ourselves, to avoid the
case when we're running the build in a non-UTF-8 locale.

https://bugzilla.gnome.org/show_bug.cgi?id=792497

demos/gtk-demo/geninclude.py
gdk/wayland/genprotocolfiles.py

index 57038a43b87df19656fd28781f906c7728f8f1d8..cd0af14e0db7352bd40ec77cd375f2e0646439c1 100755 (executable)
@@ -33,7 +33,7 @@ demos = []
 for demo_file in in_files:
     filename =  demo_file[demo_file.rfind('/')+1:]
     demo_name = filename.replace(".c", "")
-    with open(demo_file, 'r') as f:
+    with open(demo_file, 'r', encoding='utf-8') as f:
         title = f.readline().replace("/*", "").strip()
 
 
index cf4faed78f5a49a1f28c64bf3c213b8e05046f4f..1edd4e33e3e68b5ff3a18de3e92fb79e8f598d17 100755 (executable)
@@ -19,7 +19,7 @@ if pc.returncode != 0:
 
 # Now read the generated file again and remove all WL_EXPORTs
 content = ""
-with open(out_file, 'r') as content_file:
+with open(out_file, 'r', encoding='utf-8') as content_file:
     content = content_file.read()
 
 content = content.replace('WL_EXPORT ', '')